#!/sbin/openrc-run

command="/usr/bin/oauth2-proxy"
command_args="--config=/etc/oauth2-proxy/oauth2-proxy.cfg $command_args"
command_user="oa2proxy:oa2proxy"
command_background=true
directory="/var/lib/oauth2-proxy"
pidfile="/run/$RC_SVCNAME.pid"

output_log="/var/log/oauth2-proxy.log"
error_log="/var/log/oauth2-proxy.log"

extra_started_commands="reload"
description_reload="Reload configuration"

depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -d -m 755 -o $command_user /run/oauth2-proxy
	checkpath -d -m 755 -o $command_user /var/lib/oauth2-proxy

	checkpath -f -m 640 -o $command_user /etc/oauth2-proxy/oauth2-proxy.cfg
	checkpath -f -m 644 -o $command_user /var/log/oauth2-proxy.log
}

reload() {
	ebegin "Reloading configuration"

	if [ -n "$supervisor" ]; then
		$supervisor $RC_SVCNAME --signal HUP
	else
		start-stop-daemon --signal HUP --pidfile "$pidfile"
	fi
}
